<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui">

<h:head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<title>Untitled Document</title>
	<link rel="stylesheet" type="text/css" href="css/main.css" />
	<link rel="stylesheet" type="text/css" href="css/meniu.css" />
	<link rel="stylesheet" type="text/css" href="css/style.css" />

</h:head>
<h:body>

	<ui:include src="header.xhtml" />

	<h:panelGroup layout="block" id="content">

		<ui:include src="leftMenu.xhtml" />

		<h:panelGroup layout="block" id="contenRight">

			<h:panelGroup layout="block" id="header" style="margin-top: 20px;">
				<ul>
					<li id="selected"><a>Edit Report</a></li>
				</ul>
			</h:panelGroup>

			<h:panelGroup layout="block" id="contentTab">

				<h:panelGroup id="criteriaPanel"
					rendered="#{!editReportBean.columnPhase}">
					<h:form>

						<h:outputText value="#{editReportBean.error}" style="color:red" />
						<br />

						<h:panelGroup id="generalInformation">
							<h:outputText value="General Information"
								style="font-weight:bold" />
							<h:selectBooleanCheckbox value="#{editReportBean.includeUsers}">
								<f:ajax render="@form"
									execute="employeeInformation confidentialEmployeeInformation traineeInformation" />
							</h:selectBooleanCheckbox>
							<br />
							<ui:repeat value="#{editReportBean.userColumnList}"
								var="selectedColumn"
								rendered="#{editReportBean.includeUsers and not editReportBean.includeCandidates}">
								<br />

								<h:selectBooleanCheckbox value="#{selectedColumn.selected}"
									immediate="true">
									<h:outputText value="#{selectedColumn.columnLabel}" />
								</h:selectBooleanCheckbox>
								<br />

								<h:panelGroup
									rendered="#{selectedColumn.columnName == 'firstname' or selectedColumn.columnName == 'lastname'}">
									<h:outputText value="Like" />
									<h:inputText id="nameInput" value="#{selectedColumn.like}"
										validatorMessage="Only use letters">
										<f:validateRegex pattern="[a-zA-Z]*" />
									</h:inputText>
									<h:message for="nameInput" style="color:red" />
									<br />
								</h:panelGroup>

								<h:panelGroup
									rendered="#{selectedColumn.columnName == 'position'}">
									<h:outputText value="Equals" />
									<h:selectOneMenu value="#{selectedColumn.equals}">
										<f:selectItem itemValue="" itemLabel="" />
										<f:selectItems value="#{editReportBean.positionList}"
											var="pos" itemValue="#{pos}" itemLabel="#{pos}" />
									</h:selectOneMenu>
									<br />
								</h:panelGroup>

								<h:panelGroup
									rendered="#{selectedColumn.columnName == 'dob' or selectedColumn.columnName == 'employmentDate' or selectedColumn.columnName == 'medCheckUpDate'}">
									<h:panelGrid columns="4">
										<h:outputText value="After" />
										<p:calendar value="#{selectedColumn.newerThan}"
											pattern="yyyy-MM-dd" navigator="true"
											styleClass="calendarNou" />
										<h:outputText value="Before" />
										<p:calendar value="#{selectedColumn.olderThan}"
											pattern="yyyy-MM-dd" navigator="true"
											styleClass="calendarNou" />
									</h:panelGrid>
								</h:panelGroup>

							</ui:repeat>
							<hr />
						</h:panelGroup>

						<h:panelGroup id="employeeInformation">
							<h:outputText value="Employee information"
								style="font-weight:bold" />
							<h:selectBooleanCheckbox
								value="#{editReportBean.includeEmployees}">
								<f:ajax render="@form"
									execute="generalInformation confidentialEmployeeInformation" />
							</h:selectBooleanCheckbox>
							<br />
							<ui:repeat value="#{editReportBean.employeeColumnList}"
								var="selectedColumn"
								rendered="#{editReportBean.includeEmployees and (not (editReportBean.includeCandidates or editReportBean.includeTrainees))}">
								<br />

								<h:selectBooleanCheckbox value="#{selectedColumn.selected}">
									<h:outputText value="#{selectedColumn.columnLabel}" />
								</h:selectBooleanCheckbox>
								<br />

								<h:panelGroup
									rendered="#{selectedColumn.columnName == 'department'}">
									<h:outputText value="Equals" />
									<h:selectOneMenu value="#{selectedColumn.equals}">
										<f:selectItem itemValue="" itemLabel="" />
										<f:selectItems value="#{editReportBean.departmentList}"
											var="department" itemValue="#{department.id}"
											itemLabel="#{department.name}" />
									</h:selectOneMenu>
									<br />
								</h:panelGroup>

							</ui:repeat>
							<hr />
						</h:panelGroup>

						<h:panelGroup id="confidentialEmployeeInformation"
							rendered="#{controllerBean.canCreateConfidentialReport()}">
							<h:outputText value="Confidential Employee information"
								style="font-weight:bold" />
							<h:selectBooleanCheckbox
								value="#{editReportBean.includeConfidentialEmployees}">
								<f:ajax render="@form"
									execute="generalInformation employeeInformation" />
							</h:selectBooleanCheckbox>
							<br />
							<ui:repeat
								value="#{editReportBean.confidentialEmployeeColumnList}"
								var="selectedColumn"
								rendered="#{editReportBean.includeConfidentialEmployees and (not (editReportBean.includeCandidates or editReportBean.includeTrainees))}">

								<h:selectBooleanCheckbox value="#{selectedColumn.selected}">
									<h:outputText value="#{selectedColumn.columnLabel}" />
								</h:selectBooleanCheckbox>
								<br />

								<h:panelGroup
									rendered="#{selectedColumn.columnName == 'salary'}">
									<h:outputText value="More Than" />
									<h:inputText id="salaryMoreThan"
										value="#{selectedColumn.moreThan}" converterMessage="[0-9]">
										<f:convertNumber />
									</h:inputText>
									<h:outputText value="Less Than" />
									<h:inputText id="salaryLessThan"
										value="#{selectedColumn.lessThan}" converterMessage="[0-9]">
										<f:convertNumber />
									</h:inputText>
									<h:message for="salaryMoreThan" style="color:red" />
									<h:message for="salaryLessThan" style="color:red" />
									<br />
								</h:panelGroup>

							</ui:repeat>
							<hr />
						</h:panelGroup>

						<h:panelGroup id="traineeInformation">
							<h:outputText value="Trainee information"
								style="font-weight:bold" />
							<h:selectBooleanCheckbox
								value="#{editReportBean.includeTrainees}">
								<f:ajax render="@form" execute="generalInformation" />
							</h:selectBooleanCheckbox>
							<br />
							<ui:repeat value="#{editReportBean.traineeColumnList}"
								var="selectedColumn"
								rendered="#{editReportBean.includeTrainees and (not (editReportBean.includeCandidates or editReportBean.includeEmployees or editReportBean.includeConfidentialEmployees))}">
								<h:selectBooleanCheckbox value="#{selectedColumn.selected}">
									<h:outputText value="#{selectedColumn.columnLabel}" />
								</h:selectBooleanCheckbox>
								<br />
							</ui:repeat>
							<hr />
						</h:panelGroup>

						<h:panelGroup id="candidateInformation">
							<h:outputText value="Candidate information"
								style="font-weight:bold" />
							<h:selectBooleanCheckbox
								value="#{editReportBean.includeCandidates}">
								<f:ajax render="@form" />
							</h:selectBooleanCheckbox>
							<br />
							<ui:repeat value="#{editReportBean.candidateColumnList}"
								var="selectedColumn"
								rendered="#{editReportBean.includeCandidates  and (not (editReportBean.includeUsers or editReportBean.includeEmployees or editReportBean.includeConfidentialEmployees or editReportBean.includeTrainees))}">
								<h:selectBooleanCheckbox value="#{selectedColumn.selected}">
									<h:outputText value="#{selectedColumn.columnLabel}" />
								</h:selectBooleanCheckbox>
								<br />
							</ui:repeat>
							<hr />
						</h:panelGroup>

						<h:commandButton id="submit" value="Submit"
							action="#{editReportBean.getInitialResults}">
						</h:commandButton>
					</h:form>
					<br />
					<h:form rendered="#{!editReportBean.columnPhase}">
				<h:commandButton style="width:50px; height:30px;"
							image="resources/img/back-button.png"
							action="manageReports.xhtml" immediate="true"></h:commandButton>
					</h:form>
				</h:panelGroup>



				<h:panelGroup id="resultsPanel"
					rendered="#{editReportBean.columnPhase}">
					<h:form>

						<h:outputText value="#{editReportBean.error}" style="color:red" />
						<br />
						<h:outputText value="Report Name: " />
						<h:inputText id="reportName"
							value="#{editReportBean.editedReport.name}" required="true"
							requiredMessage="Must be filled" />
						<h:message for="reportName" style="color:red" />
						<br />
						<h:outputText value="Report Date: " />
						<h:outputText value="#{editReportBean.editedReport.date}">
							<f:convertDateTime pattern="yyyy-MM-dd" />
						</h:outputText>


						<br />
						<hr />
						<p:dataTable value="#{editReportBean.reportResultDTO}"
							resizableColumns="true" scrollable="true" scrollWidth="1000"
							scrollHeight="300" var="row">
							<p:columns value="#{editReportBean.selectedColumns}" width="100"
								var="col" sortBy="#{row[col]}">
								<f:facet name="header">
										#{editReportBean.header(col)}
								</f:facet>
								<f:facet name="footer">
										#{editReportBean.header(col)}
								</f:facet>
								<h:outputText value="#{row[col]}"
									rendered="#{!(col == 'dob' or col == 'medCheckUpDate' or col == 'employmentDate' or col == 'department')}" />
								<h:outputText value="#{row[col]}"
									rendered="#{col == 'dob' or col == 'medCheckUpDate' or col == 'employmentDate'}">
									<f:convertDateTime pattern="yyyy-MM-dd" />
								</h:outputText>
								<h:outputText value="#{row[col].name}"
									rendered="#{col == 'department'}">
								</h:outputText>
							</p:columns>
						</p:dataTable>

						<h:commandButton action="#{editReportBean.createReport}"
							value="Create Report" />
						<h:commandButton action="#{editReportBean.exportToXls}"
							value="Export Report" />
						<br />
					</h:form>
					<br />
					<h:form rendered="#{editReportBean.columnPhase}">
					<h:commandButton style="width:50px; height:30px;"
							image="resources/img/back-button.png"
							action="#{editReportBean.goBack}" immediate="true"></h:commandButton>
					</h:form>
				</h:panelGroup>


			</h:panelGroup>
		</h:panelGroup>
	</h:panelGroup>
</h:body>
</html>